<template>
  <div>
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </div>
</template>

<script setup>
// 使用 composable 获取 hostname
const hostname = useHostname()
// 获取主题配置
const theme = computed(() => getThemeConfig(hostname))

useHead({
  title: theme.value?.name,
  meta: [
    { name: theme.value?.name, content: theme.value?.description }
  ],
  link: [
    { rel: 'icon', type: 'image/png', href: theme.value?.favicon }
  ],
  style: [
    {
      children: `:root {\n  --primary-color: ${theme.value?.primaryColor};\n  --primary-color-hover: ${theme.value?.secondaryColor};\n}`
    }
  ],
})


const requestURL = useRequestURL()

// 获取查询参数
const queryParams = Object.fromEntries(requestURL.searchParams)
for (const key in queryParams) {
  if (key === 'channel' || key === 'network' || key === 'pid') {
    const normalizedKey = key.charAt(0).toUpperCase() + key.slice(1).toLowerCase()
    queryParams[normalizedKey] = queryParams[key]
    delete queryParams[key]
  }
}
// 调用 loadScript，传入参数
loadScript(hostname, queryParams)

if(!import.meta.server) {
  // 调用 handleAdInteraction，传入参数
  handleAdInteraction(hostname, queryParams)
}

onMounted(async () => {
  await initCpu();
});

</script>

<style scoped>
  
</style>